//Main view switcher code
jQuery && jQuery(function($){
	var selectButtons = $("#mainView_select_container a")
	var articles = $("#mainView_container > div")
	selectButtons.on("click", function(event){ //Swap articles on title click
		var index = selectButtons.index(this) 
		var visible = articles.filter(":visible")
		var selected = articles.filter(":eq("+index+")")
		if(! visible.is(selected) ) {
			visible.hide("fast");
			selected.show("fast");
		}
		selectButtons.parent().removeClass('selected');
		$(this).parent().addClass('selected');
		window.clearTimeout(mainview_timer)
		mainview_timer = window.setTimeout(mainview_timeout, mainview_timeout_delay) 
		return false
	})

	articles.on({ //Pause rotation on article hover
		mouseenter:function(){
			window.clearTimeout(mainview_timer)
		},
		mouseleave:function(){
			mainview_timer = window.setTimeout(mainview_timeout, mainview_timeout_delay) 
		}
	})

	var mainview_timeout_delay = 7000 //milliseconds
	var mainview_timeout = function() {
		var visible = articles.filter(":visible")
		var index = articles.index(visible) 
		index = (index+1) % selectButtons.length
		$(selectButtons[index]).click();
	}

	var mainview_timer = window.setTimeout(mainview_timeout, mainview_timeout_delay) 
});
